package com.example.idachuappone.promptly.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v4.widget.AutoScrollHelper;
import android.util.AttributeSet;
import android.view.View;

public class MyTextView extends View {
    private Context context;
    private String index;
    Paint paint;
    private String str;

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.paint = new Paint();
        this.context = context;
    }

    public MyTextView(Context context) {
        super(context);
        this.paint = new Paint();
        this.context = context;
    }

    public void init(String index, String str) {
        this.index = index;
        this.str = str;
    }

    protected void onDraw(Canvas canvas) {
        if (this.index == null) {
            this.index = " ";
        }
        int i = this.str.indexOf(this.index);
        float fontsize = (14.0f * this.context.getResources().getDisplayMetrics().density) + 0.5f;
        this.paint.setTextSize(fontsize);
        if (i < 0) {
            this.paint.setColor(Color.parseColor("#2f2f2f"));
            canvas.drawText(this.str, AutoScrollHelper.RELATIVE_UNSPECIFIED, (float) ((getHeight() / 2) + 10), this.paint);
        } else if (i == 0) {
            this.paint.setColor(Color.parseColor("#ff7547"));
            canvas.drawText(this.index, AutoScrollHelper.RELATIVE_UNSPECIFIED, (float) ((getHeight() / 2) + 10), this.paint);
            this.paint.setColor(Color.parseColor("#2f2f2f"));
            canvas.drawText(this.str.substring(this.index.length()), ((float) this.index.length()) * fontsize, (float) ((getHeight() / 2) + 10), this.paint);
        } else if (i == this.str.length() - this.index.length()) {
            this.paint.setColor(Color.parseColor("#2f2f2f"));
            canvas.drawText(this.str.substring(0, this.str.length() - this.index.length()), AutoScrollHelper.RELATIVE_UNSPECIFIED, (float) ((getHeight() / 2) + 10), this.paint);
            this.paint.setColor(Color.parseColor("#ff7547"));
            canvas.drawText(this.index, ((float) (this.str.length() - this.index.length())) * fontsize, (float) ((getHeight() / 2) + 10), this.paint);
        } else {
            this.paint.setColor(Color.parseColor("#2f2f2f"));
            canvas.drawText(this.str.substring(0, i), AutoScrollHelper.RELATIVE_UNSPECIFIED, (float) ((getHeight() / 2) + 10), this.paint);
            this.paint.setColor(Color.parseColor("#ff7547"));
            canvas.drawText(this.index, ((float) i) * fontsize, (float) ((getHeight() / 2) + 10), this.paint);
            this.paint.setColor(Color.parseColor("#2f2f2f"));
            canvas.drawText(this.str.substring(this.index.length() + i), ((float) (this.index.length() + i)) * fontsize, (float) ((getHeight() / 2) + 10), this.paint);
        }
        this.paint.reset();
        super.onDraw(canvas);
    }
}
